<?php

namespace Wulian\Controller;

use Common\Controller\AdminbaseController;

class AdminConfigController extends AdminbaseController {

    protected $m_Wulian_config;

    function _initialize() {
        parent::_initialize();
        $this->m_Wulian_config= D("Wulian/WlConfig");
    }

    /**
     * 列表页
     */
//    public function index(){
//
//        $count=$this->m_Wulian_config->count();
//        $page = $this->page($count, 15);
//        $list = $this->m_Wulian_config
//            ->order("create_time desc")
//            ->limit($page->firstRow , $page->listRows)
//            ->select();
//        $this->assign("page", $page->show('Admin'));
//        $this->assign("list",$list);
//        $this->display();
//    }


    /**
     * 新增
     */
    public function add(){
        $list = array();
        $config_list = $this->m_Wulian_config->where(array("config_parame"=>array("IN","proportion,flow_pool_id,h5_prefix")))->select();
        foreach($config_list AS &$citem){
            $list[$citem['config_parame']] = $citem['config_value'];
        }
        $this->assign("list",$list);
        $this->display();
    }

    /**
     * 新增数据提交
     */
    public function add_post(){
        if (IS_POST) {
            $insert = I("post.");
            foreach($insert AS $ikey =>$ivalue){
                $config = $this->m_Wulian_config->where(array("config_parame"=>$ikey))->find();
                if(empty($config)){
                    $insert = array(
                        'config_parame'=>$ikey,
                        'config_value'=>$ivalue
                    );
                    $result = $this->m_Wulian_config->add($insert);
                }else{
                    $update = array(
                        'config_value'=>$ivalue
                    );
                    $result = $this->m_Wulian_config->where(array("config_parame"=>$ikey))->save($update);
                }
            }


            addLog(3,"基础配置 修改");
            $this->success("操作成功！");
        }
    }

    /**
     * 充值提醒通知配置
     */
    public function remind(){
        $list = array();
        $config_list = $this->m_Wulian_config->where(array("config_parame"=>array("IN","remind_phone,remind_email")))->select();
        foreach($config_list AS &$citem){
            $list[$citem['config_parame']] = $citem['config_value'];
        }
        $this->assign("list",$list);
        $this->display();
    }

    /**
     * 新增数据提交
     */
    public function remind_post(){
        if (IS_POST) {
            $insert = I("post.");
            foreach($insert AS $ikey =>$ivalue){
                $config = $this->m_Wulian_config->where(array("config_parame"=>$ikey))->find();
                if(empty($config)){
                    $insert = array(
                        'config_parame'=>$ikey,
                        'config_value'=>$ivalue
                    );
                    $result = $this->m_Wulian_config->add($insert);
                }else{
                    $update = array(
                        'config_value'=>$ivalue
                    );
                    $result = $this->m_Wulian_config->where(array("config_parame"=>$ikey))->save($update);
                }
            }


            addLog(3,"流量池充值提醒配置 修改");
            $this->success("操作成功！");
        }
    }




}